<?php

session_start();

require_once("config.php");





//инициализация пользователя

if (isset($_SESSION["login"]) && isset($_SESSION["pass"])) {
	if ($userId = bpUser::isUser($_SESSION["login"], $_SESSION["pass"])) {
	   $userStatus = true;
	   $smarty->assign("userLogin", $_SESSION["login"]);
	} else {
	    unset($_SESSION["login"]);
	    unset($_SESSION["pass"]);
	    $userStatus = false;
	}
} elseif (isset($_POST["login"]) && isset($_POST["pass"])) {
    	if ($userId = bpUser::isUser($_POST["login"], md5($_POST["pass"]))) {
            $_SESSION["login"] = $_POST["login"];
            $_SESSION["pass"] = md5($_POST["pass"]);
            $userStatus = true;
            header("Location: ".DOMAIN_NAME);
    	} else {
    	    $userStatus    = false;
    	}
} else {
    $userStatus	= false;
}
define("USER_STATUS", $userStatus);
$smarty->assign("userStatus", $userStatus);


// Блок управления текущей страницей
if ($userStatus) {
	define("USER_ID", $userId);
	define("USER_NICK", $_SESSION["login"]);
	
	$smarty->display("header.tpl");
	$smarty->display("menu.tpl");

    if (isset($_REQUEST["part"])) {
        include("include/".$_REQUEST["part"].".php");    
    } else {
        include("include/main.php");
    }
$smarty->display("footer.tpl");    
} else {
    $smarty->display("enter.tpl");
}



?>